﻿using NetSystem;
using System;
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
namespace ResourceSystem
{
    public class JsonStream : IResourceReader, IResourceWriter,IDisposable
    {
        public float LoadProgress { get; private set; }

        public object Content { get; private set; }

        public AssetBundle Bundle { get; private set; }

        public byte[] Bytes { get; private set; }

        public Action OnLoadFinish;


        public object ReadResouce(string path)
        {
            string content= File.ReadAllText(path);
            return LitJson.JsonMapper.ToObject(content);
        }

        public bool WriteResource(IWriteArgs data)
        {
            JsonWriteArgs args = (JsonWriteArgs)data;
            Debug.Log(args.Content.ToJson());
            File.WriteAllText(args.Path, args.Content.ToJson()/*.Replace("\\","")*/);
          
            return true;
        }
        public void Dispose()
        {
            OnLoadFinish = null;
        }
    }
}
